package com.jinhongone.pattern.creater.builder.caseApply;

/*
 * 建造者模式实际应用：
 *   lombod中@Builder采用的就是这种方式
 *   当类的构造函数参数过多时，不直观时，可使用建造者模式思想进行改造
 * */
public class Phone {

    private String cup;
    private String screen;
    private String memory;
    private String mainBoard;

    //构造函数参数过多且不易解读，使用builder模式
    /*public Phone(String cup, String screen, String memory, String mainBoard) {
        this.cup = cup;
        this.screen = screen;
        this.memory = memory;
        this.mainBoard = mainBoard;
    }*/

    private Phone(Builder builder) {
        this.cup = builder.cup;
        this.screen = builder.screen;
        this.memory = builder.memory;
        this.mainBoard = builder.mainBoard;
    }

    @Override
    public String toString() {
        return "Phone{" +
                "cup='" + cup + '\'' +
                ", screen='" + screen + '\'' +
                ", memory='" + memory + '\'' +
                ", mainBoard='" + mainBoard + '\'' +
                '}';
    }

    public static final class Builder {
        private String cup;
        private String screen;
        private String memory;
        private String mainBoard;

        //返回 Builder可以实现链式编程（链式编程的本质就是方法会返回当前对象后续可直接调用其他方法）
        public Builder cup(String cup) {
            this.cup = cup;
            return this;
        }

        public Builder screen(String screen) {
            this.screen = screen;
            return this;
        }

        public Builder memory(String memory) {
            this.memory = memory;
            return this;
        }

        public Builder mainBoard(String mainBoard) {
            this.mainBoard = mainBoard;
            return this;
        }

        public Phone build() {
            return new Phone(this);
        }
    }
}
